var t = require("../../res/www.a9a.cn.js"),
  n = getApp(),
  e = wx.getStorageSync("COOK_U");
Page({
  data: { ic: 0, ARR: [] },
  onLoad: function (e) {
    var o = this;
    n.get_config("_ZEAI").then(function (a) {
      o.setData({ color: a.color, rgbcolor: t.c16_rgb(a.color), t: e.t }),
        n.chklogin().then(function (t) {
          t ||
            wx.showModal({
              content: rs.msg,
              confirmColor: o.data.color,
              confirmText: "朕知道了",
              showCancel: !1,
              success: function (t) {
                wx.navigateBack();
              },
            });
        });
    });
  },
  contentFn: function (t) {
    var n = t.detail.value.length;
    n > 140 &&
      (wx.showToast({ title: "最多140字", icon: "none", mask: !0 }), (n = 140)),
      this.setData({ ic: n });
  },
  upFn: function () {
    var t = this,
      n = 6 - parseInt(this.data.ARR.length);
    n <= 0
      ? wx.showToast({ title: "最多上传6张图片哦", icon: "none", mask: !0 })
      : wx.chooseMedia({
          count: n,
          mediaType: ["image"],
          sizeType: ["compressed"],
          sourceType: ["album", "camera"],
          success: function (n) {
            for (var e = t.data.ARR, o = [], a = 0; a < n.tempFiles.length; a++)
              o.push(n.tempFiles[a].tempFilePath);
            (e = e.concat(o)), t.setData({ ARR: e });
          },
        });
  },
  delFn: function (n) {
    var e = n.currentTarget.dataset.url,
      o = t.json_remove(this.data.ARR, e);
    this.setData({ ARR: o });
  },
  add_submitFn: function (o) {
    var a = this,
      s = o.detail.value.content;
    t.empty(s) || s.length > 140
      ? wx.showToast({ title: "亲，该说点什么吧～", icon: "none", mask: !0 })
      : wx.showModal({
          title: "温馨提醒",
          content:
            "确定提交么？\n以下情形话题将被删除或封号：\n1．请勿留下任何形式联系方法\n2．请勿发表涉黄涉政相关言论\n3．请勿发表辱骂攻击他人言论",
          confirmColor: a.data.color,
          cancelText: "取消",
          confirmText: "确定",
          success: function (o) {
            if (o.confirm) {
              var i = a.data.ARR,
                c = i.length;
              if (c > 0) {
                var r = Array(),
                  l = 0;
                !(function o() {
                  wx.showLoading({
                    title: "正在上传..第" + parseInt(l + 1),
                    mask: !0,
                  }),
                    wx.uploadFile({
                      url: n.WWW + "/api/wxxcx/trend.php",
                      filePath: i[l],
                      name: "pic",
                      formData: {
                        submitok: "trend_add_uppic",
                        openid: e.openid,
                      },
                      success: function (i) {
                        if (1 == (i = t.jsoneval(i.data)).flag)
                          if ((l++, r.push(i._s), l < c))
                            setTimeout(function () {
                              o();
                            }, 300);
                          else {
                            wx.hideLoading();
                            var u = r.join(",");
                            n.ajax({
                              url: "trend.php",
                              data: {
                                submitok: "trend_add",
                                content: s,
                                piclist: u,
                                openid: e.openid,
                              },
                              success: function (t) {
                                1 == t.flag
                                  ? (wx.hideLoading(),
                                    wx.showToast({
                                      title: t.msg,
                                      mask: !0,
                                      duration: 3e3,
                                    }),
                                    setTimeout(function () {
                                      a.goBack();
                                    }, 3e3))
                                  : wx.showToast({
                                      title: t.msg,
                                      icon: "none",
                                      mask: !0,
                                    });
                              },
                            });
                          }
                        else
                          wx.showModal({
                            content: i.msg,
                            confirmColor: a.data.color,
                            confirmText: "朕知道了",
                            showCancel: !1,
                            success: function (t) {
                              wx.navigateBack();
                            },
                          });
                      },
                    });
                })();
              } else
                n.ajax({
                  url: "trend.php",
                  data: { submitok: "trend_add", content: s, openid: e.openid },
                  success: function (t) {
                    1 == t.flag
                      ? (wx.showToast({
                          title: t.msg,
                          mask: !0,
                          duration: 3e3,
                        }),
                        setTimeout(function () {
                          a.goBack();
                        }, 3e3))
                      : wx.showToast({ title: t.msg, icon: "none", mask: !0 });
                  },
                });
            }
          },
        });
  },
  goBack: function () {
    var t = getCurrentPages();
    t[t.length - 2].trend_topFn(), wx.navigateBack({ delta: 1 });
  },
});
